package com.blinddate.config;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.blinddate.pojo.entity.User;
import com.blinddate.pojo.entity.UserInf;
import com.blinddate.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.List;

@Slf4j
@Configuration
@EnableScheduling
public class SchedulingConfig {

    @Autowired
    private UserService userService;

    private static final Integer endTime = 3;  //设置各种vip到3天就提醒

    @Scheduled(cron = "0 0 20 ? * *") // 每天晚上8点执行一次
    public void getToken() {
      log.info("每天晚上8点执行一次");
      //提醒用户各种vip到期
//        reachLambdaQueryWrapper.apply(true, "TO_DAYS(NOW())-TO_DAYS(date_time) = 0");
        //查询绿卡会员到期
        LambdaQueryWrapper<User> greenVipWrapper = new LambdaQueryWrapper<>();
//        green_end_time
        greenVipWrapper.apply(true,"TO_DAYS(green_end_time)-TO_DAYS(NOW()) = "+ endTime);
        List<User> greenList = userService.list(greenVipWrapper);
        for(User user : greenList){
            log.info("绿卡快过期用户:{}",user);
        }

        LambdaQueryWrapper<User> showWrapper = new LambdaQueryWrapper<>();
        showWrapper.apply(true,"TO_DAYS(show_end_time)-TO_DAYS(NOW()) = "+ endTime);
        List<User> showList = userService.list(showWrapper);
        for(User user : showList){
            log.info("下线展示快过期用户:{}",user);
        }

        LambdaQueryWrapper<User> userWrapper = new LambdaQueryWrapper<>();
        userWrapper.apply(true,"TO_DAYS(vip_time_end)-TO_DAYS(NOW()) = "+ endTime);
        List<User> vipList = userService.list(userWrapper);
        for(User user : vipList){
            log.info("vip快过期用户:{}",user);
        }
    }
}
